package com.sky.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@Slf4j
public class RedisConfiguration {

    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {

        // 创建并配置Redis模板，用于后续与Redis数据库的交互
        RedisTemplate redisTemplate = new RedisTemplate();
        // 设置Redis连接工厂，使Redis模板能够连接到Redis服务器
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        // 设置Key序列化器为String类型，确保Key在传输过程中以字符串形式序列化
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        // 返回配置好的Redis模板对象
        return redisTemplate;

    }

}
